﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Streaming_Service.Test {
    using NUnit.Framework;

    using Streaming_Service.User;

    [TestFixture]
    public class TestGenre {
        private RentIt11 client;

        [SetUp]
        public void SetUp() {
            client = new RentIt11();
        }

        [Test]
        public void ManageGenres() {
            var admin = TestUser.GetAdminSession();

            Assert.That(!client.AddGenre(new UserSession(), "Unit Testing"), "1");
            Assert.That(!client.AddGenre(admin, null), "2");
            Assert.That(!client.AddGenre(admin, ""), "3");
            Assert.That(!client.AddGenre(admin, "Drama"), "4");
            Assert.That(client.AddGenre(admin, "Unit Testing"), "5");

            Assert.That(client.GenreExists("Unit Testing"));
            Assert.That(!client.GenreExists("New Unit Testing"));

            var genres = client.ListGenres();
            Assert.That(genres.Count > 0);
            var genre = genres.Find(g => g.Name == "Unit Testing");
            Assert.That(genre.Id > 0);

            Assert.That(!client.RenameGenre(new UserSession(), genre.Id, "New Unit Testing"));
            Assert.That(!client.RenameGenre(admin, genre.Id, null));
            Assert.That(!client.RenameGenre(admin, genre.Id, ""));
            Assert.That(!client.RenameGenre(admin, genre.Id, "Action"));
            Assert.That(!client.RenameGenre(admin, -1, "New Unit Testing"));
            Assert.That(client.RenameGenre(admin, genre.Id, "New Unit Testing"));

            Assert.That(!client.RemoveGenre(new UserSession(), genre.Id));
            Assert.That(!client.RemoveGenre(admin, -1));
            Assert.That(client.RemoveGenre(admin, genre.Id));
        }

        [Test]
        public void ManageMovieGenres() {
            var admin = TestUser.GetAdminSession();
            var movie = TestMovie.RandomMovie();

            Assert.That(client.AddGenre(admin, "Unit Testing"));

            var genres = client.ListGenres();
            var genre = genres.Find(g => g.Name == "Unit Testing");
            Assert.That(genre.Id > 0);

            Assert.That(!client.AddMovieGenre(new UserSession(), movie.Id, genre.Id));
            Assert.That(!client.AddMovieGenre(admin, -1, genre.Id));
            Assert.That(!client.AddMovieGenre(admin, movie.Id, -1));
            Assert.That(client.AddMovieGenre(admin, movie.Id, genre.Id));

            Assert.That(!client.RemoveMovieGenre(new UserSession(), movie.Id, genre.Id));
            Assert.That(!client.RemoveMovieGenre(admin, -1, genre.Id));
            Assert.That(!client.RemoveMovieGenre(admin, movie.Id, -1));
            Assert.That(client.RemoveMovieGenre(admin, movie.Id, genre.Id));

            movie = client.MovieInfo(movie.Id);
            Assert.That(!movie.Genre.Exists(g => g.Id == genre.Id && g.Name == genre.Name));

            Assert.That(client.RemoveGenre(admin, genre.Id));
        }
    }
}